package com.ruoyi.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.domain.CategoryTwo;
import com.ruoyi.service.ICategoryTwoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 二级分类
 */
@RestController
@RequestMapping("/webshop/categoryTwo")
public class CategoryTwoController extends BaseController {
@Autowired
private ICategoryTwoService categoryTwoService;

// 全查
@GetMapping("/list")
public List<CategoryTwo> list(){
    List<CategoryTwo> list = categoryTwoService.list();
    return list;
}
// 根据id查一条
@GetMapping("/{id}")
public CategoryTwo getInfo(@PathVariable Long id){
    System.out.println("id = " + id);
    CategoryTwo categoryTwo = categoryTwoService.getById(id);
    return categoryTwo;
}
// 添加
@PostMapping()
public int add(@RequestBody CategoryTwo categoryTwo){
    System.out.println("categoryTwo = " + categoryTwo);
    int add = categoryTwoService.save(categoryTwo);
    return add;
}
// 修改
@PutMapping()
public int edit(@RequestBody CategoryTwo categoryTwo){
    System.out.println("categoryTwo = " + categoryTwo);
    int edit = categoryTwoService.updateById(categoryTwo);
    return edit;
}
}
